import { h, ref } from 'vue';
import { NAvatar, NImage, NTag, NSwitch, NRate } from 'naive-ui';
import { cloneDeep } from 'lodash-es';
import { FormSchema } from '@/components/Form';
import { Dicts } from '@/api/dict/dict';

import { isArray, isNullObject } from '@/utils/is';
import { getFileExt } from '@/utils/urlUtils';
import { defRangeShortcuts, defShortcuts, formatToDate } from '@/utils/dateUtil';
import { validate } from '@/utils/validateUtil';
import { getOptionLabel, getOptionTag, Option, Options, errorImg } from '@/utils/hotgo';

export class State {
  public id = 0; // id
  public code = ''; // code
  public name = ''; // name
  public desc = ''; // 解读
  public rank = 0; // 排名
  public source = ''; // 来源，开盘啦，东财，百度

  constructor(state?: Partial<State>) {
    if (state) {
      Object.assign(this, state);
    }
  }}

export function newState(state: State | Record<string, any> | null): State {
  if (state !== null) {
    if (state instanceof State) {
      return cloneDeep(state);
    }
    return new State(state);
  }
  return new State();
}



export const rules = {
  code: {
    required: true,
    trigger: ['blur', 'input'],
    type: 'string',
    message: '请输入code',
  },
};

export const schemas = ref<FormSchema[]>([
  {
    field: 'id',
    component: 'NInputNumber',
    label: 'id',
    componentProps: {
      placeholder: '请输入id',
      onUpdateValue: (e: any) => {
        console.log(e);
      },
    },
  },
  {
    field: 'stockZhASpotEmName',
    component: 'NInput',
    label: '',
    componentProps: {
      placeholder: '请输入',
      onUpdateValue: (e: any) => {
        console.log(e);
      },
    },
  },
  {
    field: 'stockZhASpotEmLastPrice',
    component: 'NInput',
    label: '',
    componentProps: {
      placeholder: '请输入',
      onUpdateValue: (e: any) => {
        console.log(e);
      },
    },
  },
  {
    field: 'stockZhASpotEmChangePercent',
    component: 'NInput',
    label: '',
    componentProps: {
      placeholder: '请输入',
      onUpdateValue: (e: any) => {
        console.log(e);
      },
    },
  },
  {
    field: 'stockZhASpotEmChangeAmount',
    component: 'NInput',
    label: '',
    componentProps: {
      placeholder: '请输入',
      onUpdateValue: (e: any) => {
        console.log(e);
      },
    },
  },
]);

export const columns = [
  {
    title: 'id',
    key: 'id',
  },
  {
    title: 'code',
    key: 'code',
  },
  {
    title: 'name',
    key: 'name',
  },
  {
    title: '解读',
    key: 'desc',
  },
  {
    title: '排名',
    key: 'rank',
  },
  {
    title: '来源，开盘啦，东财，百度',
    key: 'source',
  },
  {
    title: '',
    key: 'stockZhASpotEmName',
  },
  {
    title: '',
    key: 'stockZhASpotEmLastPrice',
  },
  {
    title: '',
    key: 'stockZhASpotEmChangePercent',
  },
  {
    title: '',
    key: 'stockZhASpotEmChangeAmount',
  },
];